package someTestExcemple.huaweiOd.container.tree.bfsOrDfs;
//华为OD机试 - 按图找最近的路 - 矩阵、最短路径问题（Java 2024 C卷 100分）
//https://blog.csdn.net/guorui_java/article/details/137025805
import java.util.*;

class Point {
    int x, y;
    int distance;

    public Point(int x, int y, int distance) {
        this.x = x;
        this.y = y;
        this.distance = distance;
    }
}
public class ShortestRoute {
    static final int[][] DIRECTIONS = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 读取地图大小
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        // 读取起点坐标
        int startX = scanner.nextInt();
        int startY = scanner.nextInt();
        // 读取终点坐标
        int endX = scanner.nextInt();
        int endY = scanner.nextInt();
        // 读取湖泊个数
        int lakeCount = scanner.nextInt();
        boolean[][] lakeMap = new boolean[m][n];
        // 标记湖泊位置
        for (int i = 0; i < lakeCount; i++) {
            int lakeX = scanner.nextInt();
            int lakeY = scanner.nextInt();
            lakeMap[lakeX][lakeY] = true;
        }

        // 调用 BFS 算法计算最短路径
        int[] result = bfs(m, n, startX, startY, endX, endY, lakeMap);
        System.out.println(result[0] + " " + result[1]);
        scanner.close();
    }

    public static int[] bfs(int m, int n, int startX, int startY, int endX, int endY, boolean[][] lakeMap) {
        boolean[][] visited = new boolean[m][n];
        int[][] pathCount = new int[m][n];
        Queue<Point> queue = new LinkedList<>();
        queue.offer(new Point(startX, startY, 0));
        visited[startX][startY] = true;
        pathCount[startX][startY] = 1;

        while (!queue.isEmpty()) {
            Point current = queue.poll();
            int x = current.x;
            int y = current.y;
            int distance = current.distance;

            if (x == endX && y == endY) {
                return new int[]{pathCount[x][y], distance};
            }

            for (int[] dir : DIRECTIONS) {
                int newX = x + dir[0];
                int newY = y + dir[1];

                if (newX >= 0 && newX < m && newY >= 0 && newY < n && !lakeMap[newX][newY]) {
                    if (!visited[newX][newY]) {
                        visited[newX][newY] = true;
                        queue.offer(new Point(newX, newY, distance + 1));
                        pathCount[newX][newY] = pathCount[x][y];
                    } else if (distance + 1 == pathCount[newX][newY]) {
                        pathCount[newX][newY] += pathCount[x][y];
                    }
                }
            }
        }

        return new int[]{0, 0};
    }
}
